package liudan.archetype.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * Description:
 * Email: liudan@ucfgroup.com
 * Title
 * Copyright: Copyright (c) 2017
 * User: liudan
 * Created on 2017/2/25 16:49
 */
public class CharacterEncodingFilter implements Filter {
    private FilterConfig filterConfig;
    private String encoding = "ISO-8895-1";

    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("CharacterEncodingFitler init.........");
        this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        System.out.println("CharacterEncodingFitler init success!");
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding(encoding);
        chain.doFilter(request,response);
    }

    public void destroy() {
        this.filterConfig = null;
        System.out.println("CharacterEncodingFitler destroy!");
    }
}
